<?php 
include("../amazon_api_class.php");
if(isset($_GET['val']) && $_GET['val']!="")
{
	

    $obj = new AmazonProductAPI();
    
    try
    {
        $result = $obj->searchProducts($_GET['val'],
                                       AmazonProductAPI::DVD,
                                       "TITLE",$_GET['pages']);
    }
    catch(Exception $e)
    {
        echo $e->getMessage();
    }
	$totalpage = $result->Items->TotalPages;
	$TotalResults = $result->Items->TotalResults;
	$saw = (($_GET['pages']*10)<$TotalResults)? ($_GET['pages']*10) : $TotalResults;
	echo "<div class='font12' style='padding-top:5px;' align='left'> Total Search Records : <b>".$saw."</b> on <b>".$TotalResults."</b></div><br>";
	foreach ($result->Items->Item as $item)
    {
      	?>
        <div class="product" style="width:370px; padding:5px 5px 5px 5px;">
        <table width="100%" style="width:370px; border:1px solid #E4E4E4; padding:3px 3px 3px 3px;" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="22%" align="center" valign="middle">
            <a href="<?php echo $item->DetailPageURL;?>" target="_blank">
            <img src="<?php echo $item->SmallImage->URL;?>" border="0" /></a>
            </td>
            <td width="69%" align="left" valign="middle" class="font12">
			<?php  
                if($item->ItemAttributes->Title!=""){echo "{$item->ItemAttributes->Title}<br>";}
				if($item->ItemAttributes->Author!=""){echo "By: {$item->ItemAttributes->Author}<br>";}
                if($item->ItemAttributes->Publisher!=""){echo "{$item->ItemAttributes->Publisher}<br>";}
				if($item->ItemAttributes->PublicationDate!=""){echo "{$item->ItemAttributes->PublicationDate}<br>";}
				?></td>
            <td width="9%" align="center" valign="middle">
            <a href="javascript:void(0);" onclick="showbooksinfo('<?php echo $item->ItemAttributes->Title;?>','<?php echo $item->ItemAttributes->Author;?>','<?php echo $item->ItemAttributes->Publisher;?>','<?php echo $item->ItemAttributes->PublicationDate;?>');">
            <img src="../images/select.png" border="0" /></a>
            </td>
          </tr>
        </table>
        </div>
        <?php
    }
	if($totalpage>$_GET['pages'])
	{
		$next = ($_GET['pages']+1)
		?>
		<a href="javascript:void(0)" id="more<?php echo $next;?>" onclick="getbooks('<?php echo $next;?>')" class="font12" style="padding:5px 5px 1px 5px;"><img src="../images/more.png" border="0" /></a>
		<?php
	}
}
for($i=1;$i<=$totalpage;$i++){
?>    
<span id="booksmore<?php echo $i;?>"></span>
<?php }?>
<script>
<?php
$moreimg = ($_GET['pages']+1);
if($moreimg>=3)
{
	for($j=($moreimg-1);$j>=1;$j--){?>
	$("#more<?php echo $j;?>").hide();
	<?php }
}
?>
function showbooksinfo(title,author,pub,pubdat)
{
	$("#booksresult").hide();
	$("#first").hide();
	$("#second").show();
	$("#bookinfo").show();
	$("#title1").val(title);
	$("#firstname1").val(author);
	$("#pub1").val(pub);
	$("#date1").val(pubdat);
}
</script>